package com.qf.util;

/**
 * --- 天道酬勤 ---
 *
 * @author QiuShiju
 * @date 2024/11/12
 * @desc 这个类用于前后端交互时 返回给前端封装json使用
 * 命名,一般有 ResultObject,R,ReturnObject
 */
public class R {

    private int code;
    private String msg;
    private Object data;

    public R() {
    }

    public R(int code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }
    public static R ok(int code,String msg ,Object data){
        R r = new R( );
        r.setCode(code);
        r.setMsg(msg);
        r.setData(data);
        return r;
    }
    public static R fail(int code,String msg){
        R r = new R( );
        r.setCode(code);
        r.setMsg(msg);
        return r;
    }
    public static R fail(String msg){
        R r = new R( );
        r.setMsg(msg);
        return r;
    }
//    public static R ok(int code,String msg){
//        R r = new R( );
//        r.setCode(code);
//        r.setMsg(msg);
//        return r;
//    }
    public static R fail(){
        R r = new R( );
        r.setCode(4000);
        r.setMsg("请求失败");
        return r;
    }

    public static R ok(){
        R r = new R( );
        r.setCode(2000);
        r.setMsg("成功");
        return r;
    }

    public static R ok(Object data){
        R r = new R( );
        r.setCode(2000);
        r.setMsg("成功");
        r.setData(data);
        return r;
    }

    public static R ok(int code,String msg){
        R r = new R( );
        r.setCode(code);
        r.setMsg(msg);
        return r;
    }
    public static R ok(String msg){
        R r = new R( );
        r.setCode(2000);
        r.setMsg(msg);
        return r;
    }

    public static R ok(int code){
        R r = new R( );
        r.setCode(code);
        r.setMsg("成功");
        return r;
    }



    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }
}
